<?php


namespace app\admin\controller\mall;

use app\admin\model\MallPromotionConfig;
use app\admin\service\TriggerService;
use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;

/**
 * @ControllerAnnotation(title="推广规则设置")
 */
class PromotionConfig extends AdminController
{
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new MallPromotionConfig();
    }
    
    /**
     * @NodeAnotation(title="查看")
     */
    public function index()
    {
        return $this->fetch();
    }
    /**
     * @NodeAnotation(title="保存")
     */
    public function save()
    {
        $this->checkPostRequest();
        $post = $this->request->post();
        try {
            foreach ($post as $key => $val) {
                $this->model
                    ->where('name', $key)
                    ->update([
                        'value' => $val,
                    ]);
            }
        } catch (\Exception $e) {
            $this->error('保存失败');
        }
        $this->success('保存成功');
    }
}